#include "mtext.h"

#include <QtWidgets>
#include "scene.h"
#include "mProcess.h"

mText::mText(mProcess *bindingItem,QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsTextItem(parent)
{
    BindingItem=bindingItem;
    setFlag(QGraphicsItem::ItemIsSelectable);
}

QVariant mText::itemChange(GraphicsItemChange change,
                     const QVariant &value)
{
    if (change == QGraphicsItem::ItemSelectedHasChanged)
    {

        emit selectedChange(this);
    }
    return value;
}

void mText::focusOutEvent(QFocusEvent *event)
{
    setTextInteractionFlags(Qt::NoTextInteraction);
    emit lostFocus(this);
    QGraphicsTextItem::focusOutEvent(event);
}

void mText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
    if (textInteractionFlags() == Qt::NoTextInteraction)
        setTextInteractionFlags(Qt::TextEditorInteraction);
    QGraphicsTextItem::mouseDoubleClickEvent(event);
}

void mText::updatePosition()
{
    int len=this->toPlainText().length();
    this->setPos(BindingItem->pos().x()-24-this->toPlainText().length()*2,BindingItem->pos().y()+24);

}
